const db=require('../db/index')

// 添加合作企业
exports.addCooperation=(req,res)=>{
    const c=req.body
    console.log("c",c); 
    const sql=`insert into cooperation(cooperationName,cooperationAddress,cooperationWebsite,cooperationPhone,cooperationIntroduce,
        cooperationEmail) values(?,?,?,?,?,?)`
    db.query(sql,[c.cooperationName,c.cooperationAddress,c.cooperationWebsite,c.cooperationPhone,c.cooperationIntroduce,c.cooperationEmail],(err,results)=>{
        console.log("c22",err); 
        if(err) return res.cc(err)
        if(results.affectedRows!==1) return res.cc('新增失败')
        res.cc('OK',0)
    })  
  }

// 获取合作企业
exports.allCooperation=(req,res)=>{
    const sql = `select * from cooperation`
    db.query(sql,(err,results) => {
        if(err) return res.cc(err)
        res.send({
            status:0,
            message:"获取成功",
            cooperation:results
        })
    })
}

// 更新企业合作
exports.editCooperation=(req,res) => {
    const c = req.body
    console.log("object",c);
    const sql = `update cooperation set cooperationName=?,cooperationAddress=?,cooperationWebsite=?,cooperationPhone=?,cooperationIntroduce=?,
    cooperationEmail=? where cooperationId=?`
    db.query(sql,[c.cooperationName,c.cooperationAddress,c.cooperationWebsite,c.cooperationPhone,c.cooperationIntroduce,
        c.cooperationEmail,c.cooperationId],(err,results) => {
            console.log("err",err);
            if(err) return res.cc(err)
            if(results.affectedRows!==1) return res.cc("更新失败")
            res.send({
                status:0,
                message:"更新成功"
            })
    })
}

// 删除企业合作
exports.deleteCooperation = (req,res) => {
    console.log('22222',req.query.cooperationId);
    const sql = `delete from cooperation where cooperationId=?`
    db.query(sql,req.query.cooperationId,(err,results) => {
        if(err) return res.cc(err)
        if(results.affectedRows!==1) return res.cc("删除失败")
        res.send({
            status:0,
            message:"删除成功"
        })
    })
}

